#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <MyString.h>
#include <string.h>
#include "BinaryTree.h"
#include "set.h"



// int main()
// {
//     srand(time(NULL));
//     BSTree *tree = InitBSTree();
    
//     for(int i = 0; i < 10; i++)
//     {
//         int a = rand() % 10;
//         printf("%d ",a);
//         InsertElement(tree,a,IsNodeBigger);
//     }

//     printf("\n前序遍历\n");
//     TravelPrev(tree);
//     printf("\n中序遍历\n");
//     TravelMid(tree);
//     printf("\n后序遍历\n");
//     TravelPost(tree);
//     printf("\n");

//     printf("输入你要删除的数:");
//     int num;
//     scanf("%d",&num);
//     RemoveByElement(tree,num);

//     TravelMid(tree);
//     printf("\n");

//     printf("树中节点数量是%d\n",GetNodeNumber(tree));

//     return 0;
// }


struct Student
{
    int id;
    MyStr name;
    int age;
};
typedef struct Student Stu;

Stu * CreateStu(const int id,const char *name,const int age)
{
    Stu *s = (Stu *)malloc(sizeof(Stu));
    if(s == NULL)
    {
        return NULL;
    }
    s->id = id;
    s->age = age;
    s->name = GetString(name);
    return s;
}

void ClearStu(void *ptr)
{
    Stu *s = (Stu *)ptr;
    //printf("释放学生对象%s\n",s->name.string);
    ClearString(&s->name);
    free(s);
}

void PrintStu(void *ptr)
{
    if(ptr == NULL)
        return;
    Stu *s = (Stu *)ptr;
    printf("学生学号:%d 学生姓名:%s 学生年龄:%d\n",s->id,s->name.string,s->age);
}

int SortByAge(void *ptr1, void *ptr2)
{
    Stu *s1 = (Stu*)ptr1;
    Stu *s2 = (Stu*)ptr2;
    return s1->age - s2->age;
}

int SortByName(void *ptr1,void *ptr2)
{
    Stu *s1 = (Stu*)ptr1;
    Stu *s2 = (Stu*)ptr2;
    return strcmp(s1->name.string , s2->name.string);
}

int SortById(void *ptr1, void *ptr2)
{
    Stu *s1 = (Stu*)ptr1;
    Stu *s2 = (Stu*)ptr2;
    return s1->id - s2->id;
}

int CheckAge(void *ptr1,void *ptr2)
{
    Stu *s = (Stu*)ptr1;
    long age = (long)ptr2;
    return s->age - age;
}





int main()
{
    set *s = InitSet(SortByAge,PrintStu,CheckAge);

    InsertSet(s,CreateStu(1,"zhangsan",21));
    InsertSet(s,CreateStu(2,"lisi",15));
    InsertSet(s,CreateStu(3,"wangwu",19));
    InsertSet(s,CreateStu(4,"liuzi",20));
<<<<<<< HEAD
    InsertSet(s,CreateStu(4,"bb",36));
    InsertSet(s,CreateStu(4,"aa",25));
=======
>>>>>>> 0979c5004e24bc00a548bec8efd3b8a77e34ab35
    TravelSet(s);
    printf("\n");
    printf("容积为:%d\n",GetSetSize(s));
    printf("========================================\n");
    printf("找到的学生为:\n");
    PrintStu((Stu*)FindSet(s,(void*)20));
    printf("========================================\n");
    RemoveSet(s,(void*)20);
    TravelSet(s);
    printf("\n");
    printf("容积为:%d\n",GetSetSize(s));
    printf("========================================\n");
    return 0;
}